﻿using System.Drawing;
using CloudShot.Editor;
using CloudShot.Editor.CanvasFigures;

namespace CloudShot.ViewModels
{
  internal class FigurePropViewModel
  {
   public CanvasObject CanvasObject { get; private set; }

    public Color BorderColor { get; set; }
    public int BorderWidth { get; set; }
    public LineType LineType { get; set; }

    //arrow
    public bool IsArrowAtStart { get; set; }
    public bool IsArrowAtEnd { get; set; }

    //backcolorpart
    public Color BackColor { get; set; }
    public byte BackgroundOpacity { get; set; }
    
    //text
    public float FontSize { get; set; }
    public Color TextColor { get; set; }
    public bool IsItalic { get; set; }
    public bool IsBold { get; set; }
    public bool IsUnderline { get; set; }
    public StringAlignment TextAlignment { get; set; }

    public bool IsTextPartVisible { get; set; }
    public bool IsBackColorPartVisible { get; set; }
    public bool IsArrowPartVisible { get; set; }
    public bool IsAddTextPartVisible { get; set; }

    public FigurePropViewModel(CanvasObject canvasObject)
    {

      CanvasObject = canvasObject;

      BorderColor = canvasObject.BorderColor;
      BorderWidth = canvasObject.BorderWidth;
      LineType = canvasObject.LineType;
      
      var rectangleBase = canvasObject as CanvasRectangleBase;
      if (rectangleBase != null)
      {
        IsBackColorPartVisible = true;
        BackColor = rectangleBase.BackColor;
        BackgroundOpacity = rectangleBase.BackgroundOpacity;
      }

      //only for exactly this type, not for derived classes
      IsAddTextPartVisible = canvasObject.GetType() == typeof(CanvasRectangle);

      var arrow = canvasObject as CanvasArrow;
      if (arrow != null)
      {
        IsArrowPartVisible = true;
        IsArrowAtStart = arrow.IsArrowAtStart;
        IsArrowAtEnd = arrow.IsArrowAtEnd;
      }


      var text = canvasObject as CanvasText;
      if (text != null)
      {
        IsTextPartVisible = true;
        FontSize = text.FontSize;
        TextColor = text.TextColor;
        IsItalic = text.IsItalic;
        IsBold = text.IsBold;
        IsUnderline = text.IsUnderline;
        TextAlignment = text.TextAlignment;
      }
    }
  }
}
